package cn.doitedu.operate

import org.apache.log4j.{Level, Logger}
import org.apache.spark.sql.{DataFrame, SparkSession}

/**
 * @Date 22.4.10
 * @Created by HANGGE
 * @Description
 */
object C07_DSL_nuion {
  Logger.getLogger("org").setLevel(Level.ERROR)
  def main(args: Array[String]): Unit = {
    // 1 获取会话
    val session = SparkSession.builder()
      .appName(this.getClass.getSimpleName)
      .master("local[*]")
      .getOrCreate()

     // 导入SQL函数和隐式
    import  session.implicits._

    // 具有丰富的操作字段的函数
    // 2 加载数据   创建DataFrame
    val df1: DataFrame = session.read.option("header" , true).option("inferSchema",true).csv("file:///D://code/doit30_spark_sql/data/csv/Teacher2.csv")
    val df2: DataFrame = session.read.option("header" , true).option("inferSchema",true).csv("file:///D://code/doit30_spark_sql/data/csv/Teacher2.csv")

    val res1 = df1.union(df2).distinct()
    val res2 = df1.unionAll(df2).orderBy('sal.desc)
    res1.show()
    res2.show()

  }
}
